import inherits from "inherits";

import PropertiesActivator from "bpmn-js-properties-panel/lib/PropertiesActivator";

import idProps from "bpmn-js-properties-panel/lib/provider/bpmn/parts/IdProps";
import nameProps from "bpmn-js-properties-panel/lib/provider/bpmn/parts/NameProps";
import processProps from "bpmn-js-properties-panel/lib/provider/bpmn/parts/ProcessProps";
import linkProps from "bpmn-js-properties-panel/lib/provider/bpmn/parts/LinkProps";
import eventProps from "bpmn-js-properties-panel/lib/provider/bpmn/parts/EventProps";
import documentationProps from "bpmn-js-properties-panel/lib/provider/bpmn/parts/DocumentationProps";

import TitleProps from "./parts/TitleProps";

function createGeneralTabGroups(
  element,
  bpmnFactory,
  canvas,
  elementRegistry,
  translate
) {
  var generalGroup = {
    id: "general",
    label: "General",
    entries: [],
  };

  idProps(generalGroup, element, translate);
  nameProps(generalGroup, element, bpmnFactory, canvas, translate);
  processProps(generalGroup, bpmnFactory, translate);

  var detailsGroup = {
    id: "details",
    label: "Details",
    entries: [],
  };

  linkProps(detailsGroup, element, translate);
  eventProps(detailsGroup, element, bpmnFactory, elementRegistry, translate);

  var documentationGroup = {
    id: "documentation",
    label: "Documentation",
    entries: [],
  };
  documentationProps(documentationGroup, element, bpmnFactory, translate);

  return [generalGroup, detailsGroup, documentationGroup];
}

function createExtensionTabGroups(element) {
  var generalGroup = {
    id: "extensionElements",
    label: "流程熟悉Tab",
    entries: [],
  };

  TitleProps(generalGroup, element);

  return [generalGroup];
}

export default function PropertiesProvider(
  eventBus,
  bpmnFactory,
  canvas,
  elementRegistry,
  translate
) {
  PropertiesActivator.call(this, eventBus);

  this.getTabs = function (element) {
    var generalTab = {
      id: "general",
      label: "General",
      groups: createGeneralTabGroups(
        element,
        bpmnFactory,
        canvas,
        elementRegistry,
        translate
      ),
    };

    var varextensionTab = {
      id: "extension",
      label: "流程熟悉TabExtension",
      groups: createExtensionTabGroups(element),
    };

    return [generalTab, varextensionTab];
  };
}

inherits(PropertiesProvider, PropertiesActivator);
